package com.pituruh.utils;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class ScheduleShelterXMLHandler extends DefaultHandler {

	Boolean currentElement = false;
	String currentValue = null;
	public static ScheduleShelterSitesList sitesList = null;

	public static ScheduleShelterSitesList getSitesList() {
		return sitesList;
	}

	public static void setSitesList(ScheduleShelterSitesList sitesList) {
		ScheduleShelterXMLHandler.sitesList = sitesList;
	}

	/**
	 * Called when tag starts ( ex:- <name>AndroidPeople</name> -- <name> )
	 */
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {

		currentElement = true;

		if (localName.equals("TJRoute")) {
			/** Start */
			sitesList = new ScheduleShelterSitesList();
		} 

	}

	/**
	 * Called when tag closing ( ex:- <name>AndroidPeople</name> -- </name> )
	 */
	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {

		currentElement = false;

		/** set value */
		if (localName.equalsIgnoreCase("route"))
			sitesList.setRoute(currentValue);
		else if (localName.equalsIgnoreCase("time"))
			sitesList.setTime(currentValue);
	}

	/**
	 * Called to get tag characters ( ex:- <name>AndroidPeople</name> -- to get
	 * AndroidPeople Character )
	 */
	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {

		if (currentElement) {
			currentValue = new String(ch, start, length);
			currentElement = false;
		}

	}

}